/* dispose */
if (!Symbol.dispose)
  Symbol.dispose = Symbol('Symbol.dispose');
if (!Symbol.asyncDispose)
  Symbol.asyncDispose = Symbol('Symbol.asyncDispose');

/* Promise.withResolvers */
if (typeof Promise.withResolvers === 'undefined') {
  Promise.withResolvers = function () {
    let resolve, reject;
    const promise = new Promise((res, rej) => {
      resolve = res;
      reject = rej;
    });
    return { promise, resolve, reject };
  };
}

/* window.requestIdleCallback */
if (typeof window.requestIdleCallback !== 'function') {
  window.requestIdleCallback = function (callback, options) {
    const start = Date.now();
    return setTimeout(() => {
      callback({
        didTimeout: false,
        timeRemaining() {
          return Math.max(0, 50 - (Date.now() - start));
        },
      });
    }, 1);
  };

  window.cancelIdleCallback = function (id) {
    clearTimeout(id);
  };
}
